package com.thot.timyag.core;

import lombok.Getter;
import lombok.Setter;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;

/**
 * @author yangjf
 * @time 2019-07-04 18:22
 */
@Getter
@Setter
public class ApiInfo {
    private String url;
    private String method;


    public ApiInfo() {
    }

    public ApiInfo(RequestMappingInfo mappingInfo) {
        this.url = mappingInfo.getPatternsCondition().toString();
        this.url = this.url.substring(1, this.url.length() - 1);
        this.method = mappingInfo.getMethodsCondition().toString();
        this.method = this.method.substring(1, this.method.length() - 1);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof ApiInfo)) {
            return false;
        }

        ApiInfo model2 = (ApiInfo) o;
        if (null != this.url && this.url.equals(model2.getUrl())
                && null != this.method && this.method.equals(model2.getMethod())) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + url.hashCode();
        result = 31 * result + method.hashCode();
        return result;
    }
}
